package trafficsimulator;

public class TrafficSimulator
{

    public static void main(String[] args)
    {
        Map map = new Map(51, 51, 5);
        Car a = new Car(1, 'S', 5, 5, 28, 10, 'A');
        Car b = new Car(1, 'N', 20, 20, 40, 36, 'B');
        char[][] display = map.getMap();
        a.createRoute(map);
        b.createRoute(map);
        char[] route = a.getRoute();
        char[] route1 = b.getRoute();
        map.setCar(a);
        map.setCar(b);
        try
        {
        for (char element : route)
        {
            if (element != '0')
            {
                System.out.print(element + ",");
            }
        }
        System.out.println();
        for (char element : route1)
        {
            if (element != '0')
            {
                System.out.print(element + ",");
            }
        }
        System.out.println();
        for (int i = 0; i < map.getMapYSize(); i++)
        {
            for (int j = 0; j < map.getMapXSize(); j++)
            {
                System.out.print(display[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
        for (int i = 0; i < route.length; i++)
        {
            if (route[i] != '0')
            {
                a.step();
                map.setCar(a);
            }
        }
        for (int i = 0; i < route.length; i++)
        {
            if (route[i] != '0')
            {
                b.step();
                map.setCar(b);
            }
        }
        for (int i = 0; i < map.getMapYSize(); i++)
        {

            for (int j = 0; j < map.getMapXSize(); j++)
            {

                System.out.print(display[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println("\n" + "Car has arrived? " + a.hasArrived());
        }
        catch(ArrayIndexOutOfBoundsException e)
        {
            System.out.println("Index out of bounds.");
            System.out.println("("+a.getX()+","+a.getY()+")");
        }
    }
}
